<table id="sysres_res_enum_${action_id}_datagrid" ></table>
<script type="text/javascript">

$(function(){
	
	$('#sysres_res_enum_${action_id}_datagrid').datagrid({
		iconCls:'icon-save',
		width:'auto',
		height:'auto',
		nowrap: false,
		fit:true,
		fitColumns:true,
		striped: true,
		url:'${request.contextPath}${namespace?default('')}/mp/sysres/resenum-datagrid.json?key=${key?default('')}&code=${code?default(0)}&type=${type?default('')}&multi=${multi?string('true','false')}',
		sortName: 'ordinal',
		sortOrder: 'asc',
		remoteSort: true,
		singleSelect : true,
		idField:'id',
		onBeforeLoad:function(){$('#sysres_res_enum_${action_id}_datagrid').datagrid('unselectAll');},
		columns:[[
					{field:'name',title:'${action.getDatagridTitle('name')}',width:150,align:'center',sortable:true},
					{field:'keyValue',title:'${action.getDatagridTitle('keyValue')}',width:150,align:'center',sortable:true},
					{field:'comments',title:'${action.getDatagridTitle('comments')}',width:150,align:'center',sortable:true},
					<#if multi>
					{field:'parent',title:'${action.getDatagridTitle('parent')}',width:150,align:'center',sortable:true,formatter:function(val, rec){
						return rec.parent.name;
					}},
					</#if>
					{field:'caozuo',title:'${action.getProperty('net.esj.background.message','bg.datagrid.action')}',width:80,align:'center',sortable:false,formatter:function(val, rec){
						return '<a href="javascript:;;" onclick="sysres_res_enum_${action_id}_edit(\''+rec.id+'\')" >${action.getProperty('net.esj.background.message','bg.datagrid.modify')}</a>&nbsp;|&nbsp;<a href="javascript:;;" onclick="sysres_res_enum_${action_id}_delete(\''+rec.id+'\')" >${action.getProperty('net.esj.background.message','bg.datagrid.delete')}</a>';
					}}
				]],
		pagination:true,
		rownumbers:true,
		toolbar:[{
			id:'btnadd',
			text:'${action.getProperty('net.esj.background.message','bg.datagrid.add')}',
			iconCls:'icon-add',
			handler:function(){
				$('<div/>').dialog({
					href:'${request.contextPath}${namespace?default('')}/mp/sysres/resenum-form.htm?key=${key?default('')}&code=${code?default(0)}&type=${type?default('')}&action_id=${action_id}&multi=${multi?string('true','false')}',
					width:500,   
					height:400,   
					title: '${action.getText('form.add.title')}',
					modal:true,
					maximizable:false,
					collapsible:false,
					minimizable:false,
					resizable:false,
					buttons:[{iconCls : 'icon-ok',
								text:'${action.getProperty('net.esj.background.message','bg.datagrid.save')}',
								handler:function(){
									var d = $(this).closest('.window-body');
									$('#sysres_res_enum_${action_id}_form').form('submit', {
										url : '${request.contextPath}${namespace?default('')}/mp/sysres/resenum-add.json?key=${key?default('')}&code=${code?default(0)}&type=${type?default('')}',
										onSubmit: function(){
											return $(this).form('validate');
				        				},
										success : function(json) {
											eval("json="+json);
											$.messager.alert(json.title,json.msg,json.level);
											d.dialog('destroy');
											$("#sysres_res_enum_${action_id}_datagrid").datagrid('reload');
										}
									});
								}},
								{iconCls : 'icon-undo',
								text:'${action.getProperty('net.esj.background.message','bg.datagrid.reset')}',
								handler:function(){
									$('#sysres_res_enum_${action_id}_form').form('clear');
								}}],
					onClose : function() {
						$(this).dialog('destroy');
					}
				});
			}
		}]
	});

});

function sysres_res_enum_${action_id}_edit(id) {
	$('<div>').dialog({
		href : '${request.contextPath}${namespace?default('')}/mp/sysres/resenum-edit.htm?key=${key?default('')}&code=${code?default(0)}&type=${type?default('')}&action_id=${action_id}',
		width:500,   
		height:400,   
		modal : true,
		title : '${action.getText('form.edit.title')}',
		buttons : [ {
			text : '${action.getProperty('net.esj.background.message','bg.datagrid.edit')}',
			iconCls : 'icon-edit',
			handler : function() {
				var d = $(this).closest('.window-body');
				$('#sysres_res_enum_${action_id}_edit_form').form('submit', {
					url : '${request.contextPath}${namespace?default('')}/mp/sysres/resenum-update.json?key=${key?default('')}&code=${code?default(0)}&type=${type?default('')}',
					onSubmit: function(){
						return $(this).form('validate');
    				},
					success : function(json) {
						eval("json="+json);
						$.messager.alert(json.title,json.msg,json.level);
						d.dialog('destroy');
						$("#sysres_res_enum_${action_id}_datagrid").datagrid('reload');
					}
				});
			}
		} ],
		onClose : function() {
			$(this).dialog('destroy');
		},
		onLoad : function() {
			$('#sysres_res_enum_${action_id}_edit_form').form('load', '${request.contextPath}${namespace?default('')}/mp/sysres/resenum-load.json?key=${key?default('')}&code=${code?default(0)}&type=${type?default('')}&id='+id+'&n='+Math.random());
		}
	});
}

function sysres_res_enum_${action_id}_delete(id){
	$.messager.confirm('${action.getText('bg.message.info')}', '${action.getText('property.delete.alert')}', function(b) {
		if (b) {
			$.ajax({
				url : '${request.contextPath}${namespace?default('')}/mp/sysres/resenum-delete.json?key=${key?default('')}&code=${code?default(0)}&type=${type?default('')}',
				data:{deletes : id},
				dataType : 'JSON',
				success : function(json) {
					$.messager.alert(json.title,json.msg,json.level);
					$("#sysres_res_enum_${action_id}_datagrid").datagrid('reload');
					$('#sysres_res_enum_${action_id}_datagrid').datagrid('clearSelections');
				}
			});
		}
	});
}
</script>	